/**
 *  @file X509Certificate.h
 */
#ifndef _X509CERTIFICATE_H_
#define _X509CERTIFICATE_H_

#include "../../common/BaseObject.h"
#include "../../text/CFString.h"
#include "../../collections/BinBuf.h"
#include "../../collections/ArrayT.h"
#include "../../collections/KeyValueListT.h"
#include "../../util/DateTime.h"

namespace cppflib
{

namespace security
{

namespace cert
{

/**
 *  A class to wrap around a X509Certificate
 */
class _DLLAPI X509Certificate : public BaseObject
{
private:
    ptrany_t x509Cert; 
    bool isFreeCert;   

private:
    X509Certificate(void);
    void ReleaseBeforeThrowing();

public:
    //! type of extension
    typedef enum 
    {
       EXT_LIST,
       EXT_STRING,
       EXT_RAW,
       EXT_UNKNOWN
    } extensiontype_t;

public:
    X509Certificate(ptrany_t x509Cert, bool isFreeCert);
    virtual ~X509Certificate(void);

    int GetVersion();
    CFString GetIssuerName();
    bool GetOneValueFromIssuerName(const CFString &longOrShortName, CFString &outVal);
    CFString GetSubjectName();
    bool GetOneValueFromSubjectName(const CFString &longOrShortName, CFString &outVal);
    util::DateTime GetNotBefore();
    util::DateTime GetNotAfter();
    bool IsValid(util::DateTime &d);

    collections::ArrayByte *GetEncoded();

    int GetExtensionCount();
    bool GetExtensionName(int index, CFString &extName);
    bool GetExtensionType(int index, extensiontype_t &type);
    bool GetExtensionValueList(int index, collections::NameValueList &extValList);
    bool GetExtensionValueString(int index, CFString &extValString);
    bool GetExtensionValueRaw(int index, collections::BinBuf &extValBin);

public:
    PUBLIC X509Certificate * FromDER(pcwstr_t DERPath);
    PUBLIC X509Certificate * FromPEM(pcwstr_t PEMPath);
    
};

} // end of namespace cert

} // end of namespace security

} // end of namespace cppflib

#endif
